<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        #content {
            padding-top: 80px;
        }
    </style>
    <link href="/3rd/bs/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/3rd/bs/css/signin.css" rel="stylesheet" type="text/css" />
    <title>登录 - 紫荆之声</title>
</head>
<body>
    <header class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" style="cursor:default" id="nav-title"></a>
            </div>

            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav" id="nav-li"></ul>
                <ul class="nav navbar-nav navbar-right" id="nav-li-right"></ul>
            </div>
        </div>
    </header>

    <div id="content"></div>

    <footer class="bs-footer" role="contentinfo">
        <hr>
        <div class="container" id="footer" style="text-align: center"></div>
    </footer>

<script type="text/template" id="tpl-nav-title">
“紫荆之声”票务管理系统
</script>

<script type="text/template" id="tpl-nav-li">

</script>

<script type="text/template" id="tpl-nav-li-right">

</script>

<script type="text/template" id="tpl-content">
    <div class="container">
        <form id="form-login" class="form-signin" action="/api/a/login" method="post" role="form">

            <h2 class="form-signin-heading">登录</h2>

            <div id="alert"></div>

            <input type="text" id="inputUsername" name="username" class="form-control" placeholder="用户名" required autofocus>

            <input type="password" id="inputPassword" name="password" class="form-control" placeholder="密码" required>

            <input id="loginnow" type="submit" class="btn btn-block btn-primary" value="登录">
        </form>
    </div>
</script>

<script type="text/template" id="tpl-footer">
    <a href="http://www.xuetangx.com/" target="_blank">学堂在线</a>
    <a href="http://www.tsinghua.edu.cn/" target="_blank">清华大学</a>
    <a href="https://github.com/ThssSE" target="_blank">软件工程</a><br>
    &copy; 2016
</script>

<script src="/3rd/jquery.js"></script>
<script src="/3rd/bs/js/bootstrap.min.js"></script>
<script src="/3rd/swig.js"></script>
<script src="/js/base.js"></script>
<script src="/js/base_admin.js"></script>

<script>
    var locals = {};
    var renderTemplate = function (name) {
        $('#' + name).html(swig.render($('#tpl-' + name).html(), {locals: locals}));
    };
    var render = function () {
        renderTemplate('nav-title');
        renderTemplate('nav-li');
        renderTemplate('nav-li-right');
        renderTemplate('content');
        renderTemplate('footer');
    };
    $(function () {
        swig.setDefaultTZOffset(new Date().getTimezoneOffset());
        render();
        $('#loginnow').attr('disabled', true);
        function showError(message, dom){
            $('#alert').addClass('alert alert-danger');
            $('#alert').text(message);
            dom.focus();
        }
        api.get('/api/a/login', {}, function (data) {
            window.location.href = '/a/activity/list';
        }, function () {
            $('#loginnow').attr('disabled', false);
            api.form($('#form-login'), function (data) {
                if (urlParam.next) {
                    window.location.href = urlParam.next;
                } else {
                    window.location.href = '/a/activity/list';
                }
            }, function (errno, errmsg, e) {
                var hint = errmsg;
                if (e) {
                    hint += ": " + e;
                }
                showError(hint, $(window));
            }, function (form) {
                $('#loginnow').attr('disabled', true);
            }, function () {
                $('#loginnow').attr('disabled', false);
            });
        });
    });
</script>
</body>
</html>